﻿
#region Usings

using PolyGameEngine.Tools;


using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;

#endregion

namespace PolyGameEngine.MenuSystem
{
    public class Help
    {
        GameState gameState
        {
            get { return PhysicsGame.gamestate; }
            set { PhysicsGame.ChangeGameState( value); }
        }
        ContentManager content;
        Viewport viewport;
        Texture2D background;
        Texture2D oshadow;
        Texture2D[] helpPics = new Texture2D[2];
        float K = 0.03f;
        bool grow = true;
        string[] HelpList = new string[2];
        int selected = 0;
        SpriteFont[] font;

        public Help(ContentManager Content, Viewport Viewport, SpriteFont[] Font)
        {

            viewport = Viewport;
            content = Content;
            font = Font;
            HelpList[0] = "Controls";
            HelpList[1] = "Tiles & Obstacles";

            background = content.Load<Texture2D>("Menu/fire");
            oshadow = content.Load<Texture2D>("Menu/OuterShadow");
            helpPics[0] = content.Load<Texture2D>("Menu/Controls");
            helpPics[1] = content.Load<Texture2D>("Menu/Tiles1");

        }

        public void update()
        {
            InputMan.Update();
            if (InputMan.OnPress(Keys.Escape))
            {
                AudioMan.PlayCue("Trampoline");
                gameState = GameState.Menu;
            }

            if (K >= 1f)
                grow = false;
            if (K <= 0.8f)
                grow = true;
            if (grow)
                K += 0.005F;
            else
                K -= 0.005f;


            if (InputMan.OnPress(Keys.S))
            {
                AudioMan.PlayCue("Menu Switch");

                if (++selected > HelpList.Length - 1)
                {
                    selected = 0;
                }
            }

            if (InputMan.OnPress(Keys.W))
            {
                AudioMan.PlayCue("Menu Switch");

                if (--selected < 0)
                {
                    selected = HelpList.Length - 1; ;
                }
            }



        }

        public void draw(SpriteBatch sb)
        {
            sb.Draw(background, new Rectangle(0, 0, background.Width, background.Height), Color.White);
            sb.Draw(oshadow, new Rectangle(0, 0, oshadow.Width, oshadow.Height), Color.White);

            Vector2 controlposition = new Vector2(viewport.Width - (int)(viewport.Width * 0.1), viewport.Height / 2);
            Vector2 textposition = new Vector2(viewport.Width - (int)(viewport.Width * 0.9), (int)(viewport.Height * 0.1));

            for (int i = 0; i <= HelpList.Length - 1; i++)
            {

                if (selected == i)
                {
                    sb.Draw(helpPics[i], controlposition - new Vector2(helpPics[i].Width / 2, 0), new Rectangle(0, 0, helpPics[i].Width, helpPics[i].Height), Color.White, 0, new Vector2(helpPics[i].Width / 2, helpPics[i].Height / 2), 1.2f, SpriteEffects.None, 0.5f);
                    sb.DrawString(font[0], HelpList[i], textposition, Color.Red, 0, Vector2.Zero, K, SpriteEffects.None, 0);
                }
                else
                    sb.DrawString(font[0], HelpList[i], textposition, Color.Black);


                textposition.Y += 100;
            }


        }



    }
}
